package com.oasys.controller;

import com.oasys.entity.dto.RoleUserDto;
import com.oasys.entity.po.RolePo;
import com.oasys.entity.vo.RoleUserVo;
import com.oasys.entity.vo.RoleVo;
import com.oasys.enums.OaResponseCode;
import com.oasys.service.RoleService;
import com.oasys.utils.ResponseResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2022/5/26
 **/
@RestController
@RequestMapping("/getRoleInfo")
@Slf4j
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/getRoleUserInfo")
    @ApiOperation("获取角色用户信息")
    public ResponseResult<List<RoleUserDto>> getRoleUserInfo(){
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),null,roleService.getRoleUserInfo());
    }

    /**
     * 保存角色菜单信息
     * @param roleUserVo
     * @return
     */
    @PostMapping("/saveMenuRoleInfo")
    public ResponseResult<Boolean> saveMenuRoleInfo(@RequestBody RoleUserVo roleUserVo){
        return roleService.saveMenuRoleInfo(roleUserVo);
    }

    @GetMapping("/getAllRoleInfo")
    @ApiOperation("获取所有角色信息")
    public ResponseResult<List<RolePo>> getAllRoleInfo(@RequestParam String roleName){
        return roleService.getAllRoleInfo(roleName);
    }

    @PostMapping("/addRole")
    @ApiOperation("添加角色")
    public ResponseResult<Boolean> addRole(@RequestParam String roleName){
        log.info("角色名称:{}",roleName);
        return roleService.addRole(roleName);
    }
    @PostMapping("/updateRole")
    @ApiOperation("修改角色")
    public ResponseResult<Boolean> updateRole(@RequestBody RoleVo roleVo){
        return roleService.updateRole(roleVo);
    }

    @GetMapping("/delRole/{roleId}")
    @ApiOperation("删除角色")
    public ResponseResult<Boolean> delRole(@PathVariable("roleId") Long roleId){
        return roleService.delRole(roleId);
    }
}
